import { Router, Route, Switch, Redirect } from 'react-router-dom'
// jsconfig.json 配置绝对路径，从项目文件夹的 src 开始查找
// import Layout from 'pages/Layout'
// import Login from 'pages/Login'
import AuthRoute from 'components/AuthRoute'
import history from 'utils/history'
import React, { Suspense } from 'react'
import Loading from 'components/Loading'
const Login = React.lazy(() => import('pages/Login'))
const Layout = React.lazy(() => import('pages/Layout'))

function App() {
  return (
    <Router history={history}>
      <div className='App'>
        {/* <Link to="/login">登录</Link>
        <Link to="/home">首页</Link> */}
        {/* fallback: 如果组件还没有加载，默认会显示 fallback 的内容 */}
        <Suspense fallback={<Loading />}>
          {/* 配置路由的规则 */}
          <Switch>
            <Redirect exact from='/' to='/home'></Redirect>
            <AuthRoute path='/home' component={Layout}></AuthRoute>
            <Route path='/login' component={Login}></Route>
            {/* 配置一个404组件 */}
          </Switch>
        </Suspense>
      </div>
    </Router>
  )
}

export default App
